package p270jp.pxv.android.viewholder;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.view.View;
import android.view.ViewGroup;
import androidx.recyclerview.widget.LinearLayoutManager;
import java.util.ArrayList;
import java.util.List;
import p014ae.C0135p4;
import p014ae.C0146r;
import p014ae.View$OnClickListenerC0151s;
import p014ae.View$OnClickListenerC0156s7;
import p014ae.View$OnClickListenerC0163u;
import p045be.C1060c;
import p045be.HorizontalLayoutLiveAdapter;
import p071cd.Functions;
import p134ei.AnalyticsAction;
import p144f1.C3017s;
import p187gl.PixivRequest;
import p270jp.pxv.android.R;
import p270jp.pxv.android.activity.PopularLiveListActivity;
import p270jp.pxv.android.activity.WebViewActivity;
import p270jp.pxv.android.model.AppApiSketchLive;
import p270jp.pxv.android.model.SketchLiveListType;
import p270jp.pxv.android.response.PixivResponse;
import p270jp.pxv.android.widget.SnappyRecyclerView;
import p309lb.FirebaseRemoteConfig;
import p314lg.ViewHolderPopularLiveListBinding;
import p325m0.MutabilityOwnership;
import p336mb.ConfigGetParameterHandler;
import p350mp.Timber;
import p370ni.InfoType;
import p451qm.CarouselItemDecoration;
import p521th.SolidItemViewHolder;
import p569vd.C6830b;
import p645yc.AndroidSchedulers;
import p671zc.CompositeDisposable;
import p671zc.Disposable;
import p677zi.PixivImageLoader;

@SuppressLint({"RxJava2MissingCompositeDisposableClear"})
/* renamed from: jp.pxv.android.viewholder.PopularLiveListViewHolder */
/* loaded from: classes2.dex */
public class PopularLiveListViewHolder extends SolidItemViewHolder {
    private final HorizontalLayoutLiveAdapter adapter;
    private final ViewHolderPopularLiveListBinding binding;
    private final CompositeDisposable compositeDisposable;
    private boolean liveNotFound;
    private final AnalyticsAction openViaAction;
    private boolean requesting;

    private PopularLiveListViewHolder(ViewHolderPopularLiveListBinding y7Var, CompositeDisposable aVar, AnalyticsAction aVar2, PixivImageLoader aVar3) {
        super(y7Var.f2666e);
        this.binding = y7Var;
        this.compositeDisposable = aVar;
        this.openViaAction = aVar2;
        HorizontalLayoutLiveAdapter lVar = new HorizontalLayoutLiveAdapter(aVar3);
        this.adapter = lVar;
        SnappyRecyclerView snappyRecyclerView = y7Var.f22506s;
        this.itemView.getContext();
        snappyRecyclerView.setLayoutManager(new LinearLayoutManager(0, false));
        SnappyRecyclerView snappyRecyclerView2 = y7Var.f22506s;
        Context context = snappyRecyclerView2.getContext();
        MutabilityOwnership.m3745m(context, "context");
        Resources resources = context.getResources();
        snappyRecyclerView2.m10871g(new CarouselItemDecoration(resources.getDimensionPixelSize(R.dimen.carousel_item_margin_outside), resources.getDimensionPixelSize(R.dimen.carousel_item_margin_inside)));
        y7Var.f22506s.setAdapter(lVar);
        y7Var.f22505r.setOnClickListener(new View$OnClickListenerC0151s(this, 27));
        ConfigGetParameterHandler gVar = FirebaseRemoteConfig.m3858a().f21057h;
        String c = ConfigGetParameterHandler.m3613c(gVar.f22991c, "android_live_news_button_url");
        if (c != null) {
            gVar.m3615a("android_live_news_button_url", ConfigGetParameterHandler.m3614b(gVar.f22991c));
        } else {
            c = ConfigGetParameterHandler.m3613c(gVar.f22992d, "android_live_news_button_url");
            if (c == null) {
                ConfigGetParameterHandler.m3612d("android_live_news_button_url", "String");
                c = "";
            }
        }
        if (!c.isEmpty()) {
            y7Var.f22507t.setVisibility(0);
            y7Var.f22507t.setOnClickListener(new View$OnClickListenerC0156s7(y7Var, c, 9));
        }
    }

    public static PopularLiveListViewHolder createViewHolder(ViewGroup viewGroup, CompositeDisposable aVar, AnalyticsAction aVar2, PixivImageLoader aVar3) {
        return new PopularLiveListViewHolder((ViewHolderPopularLiveListBinding) C1060c.m10358a(viewGroup, R.layout.view_holder_popular_live_list, viewGroup, false), aVar, aVar2, aVar3);
    }

    /* renamed from: e */
    public static /* synthetic */ void m4408e(PopularLiveListViewHolder popularLiveListViewHolder, PixivResponse pixivResponse) {
        popularLiveListViewHolder.lambda$reloadIfNeeded$4(pixivResponse);
    }

    /* renamed from: h */
    public static /* synthetic */ void m4407h(PopularLiveListViewHolder popularLiveListViewHolder, Throwable th) {
        popularLiveListViewHolder.lambda$reloadIfNeeded$6(th);
    }

    /* renamed from: i */
    public static /* synthetic */ void m4406i(PopularLiveListViewHolder popularLiveListViewHolder) {
        popularLiveListViewHolder.lambda$reloadIfNeeded$3();
    }

    /* renamed from: j */
    public static /* synthetic */ void m4405j(PopularLiveListViewHolder popularLiveListViewHolder, View view) {
        popularLiveListViewHolder.lambda$new$0(view);
    }

    /* renamed from: k */
    public static /* synthetic */ void m4404k(PopularLiveListViewHolder popularLiveListViewHolder, View view) {
        popularLiveListViewHolder.lambda$reloadIfNeeded$5(view);
    }

    public void lambda$new$0(View view) {
        Context context = this.itemView.getContext();
        Context context2 = this.itemView.getContext();
        int i = PopularLiveListActivity.f18529f0;
        context.startActivity(new Intent(context2, PopularLiveListActivity.class));
    }

    public static void lambda$new$1(ViewHolderPopularLiveListBinding y7Var, String str, View view) {
        Context context = y7Var.f2666e.getContext();
        context.startActivity(WebViewActivity.m4684S0(context, str));
    }

    public void lambda$reloadIfNeeded$2(Disposable bVar) {
        this.requesting = true;
        this.binding.f22504q.m4595d(InfoType.LOADING, null);
    }

    public /* synthetic */ void lambda$reloadIfNeeded$3() {
        this.requesting = false;
    }

    public void lambda$reloadIfNeeded$4(PixivResponse pixivResponse) {
        List<AppApiSketchLive> d = C3017s.m6472d(pixivResponse.lives);
        boolean z = ((ArrayList) d).size() == 0;
        this.liveNotFound = z;
        if (z) {
            this.binding.f22504q.m4595d(InfoType.NOT_FOUND, null);
            return;
        }
        this.binding.f22504q.m4598a();
        HorizontalLayoutLiveAdapter lVar = this.adapter;
        AnalyticsAction aVar = this.openViaAction;
        lVar.f4764d = d;
        lVar.f4765e = aVar;
        lVar.f3606a.m10780b();
    }

    public /* synthetic */ void lambda$reloadIfNeeded$5(View view) {
        reloadIfNeeded();
    }

    public void lambda$reloadIfNeeded$6(Throwable th) {
        this.binding.f22504q.m4595d(InfoType.SMART_ERROR, new View$OnClickListenerC0163u(this, 27));
        Timber.f23100a.mo3514p(th);
    }

    private void reloadIfNeeded() {
        if (!this.requesting && !this.liveNotFound) {
            if (this.adapter.mo1393c() > 0) {
                this.adapter.f3606a.m10780b();
            } else {
                this.compositeDisposable.mo82c(PixivRequest.m5809h(SketchLiveListType.POPULAR).m986o(AndroidSchedulers.m334a()).m992i(new C0146r(this, 21)).m991j(new C0135p4(this, 0)).m984q(new C0135p4(this, 22), new C6830b(this, 23), Functions.f5386c, Functions.f5387d));
            }
        }
    }

    @Override // p521th.SolidItemViewHolder
    public void onBindViewHolder(int i) {
        reloadIfNeeded();
    }
}
